<template>
  <div class="default-box" :style="{ width, height }">
    <slot>
      <img v-if="showImg" src="@/assets/img/emptyState.svg" alt="暂无文件" />
    </slot>
    <slot name="title">
      <h4 v-if="title">{{ title }}</h4>
    </slot>
    <a-button v-if="showButton" @click="onClickButton">{{ buttonText }}</a-button>
  </div>
</template>

<script lang="ts" setup>
  withDefaults(
    defineProps<{
      title?: string
      width?: string
      height?: string
      showButton?: boolean
      showImg?: boolean
      buttonText?: string
    }>(),
    {
      title: '数据加载失败',
      width: '100%',
      height: '100%',
      showButton: false,
      showImg: true,
      buttonText: '返回首页'
    }
  )

  const emits = defineEmits<{
    (e: 'onClickButton'): void
  }>()

  const onClickButton = () => {
    emits('onClickButton')
  }
</script>

<style lang="less" scoped>
  .default-box {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 100%;
    height: 100%;
    gap: 20px 0;

    h4 {
      font-size: 18px;
      text-align: center;
      color: @text02;
      font-weight: 400;
    }
  }
</style>
